package com.gc.server.manager;

import java.util.List;

import com.gc.exception.CantEvaluateException;
import com.gc.exception.DuplicatedException;
import com.gc.exception.InvalidateException;
import com.gc.exception.RecordNotFoundException;
import com.gc.model.DramaEvaluateModel;
import com.gc.model.DramaModel;
import com.gc.model.UserModel;
import com.gc.protocol.GcManager;
import com.gc.server.dao.drama.DramaDao;
import com.gc.server.dao.drama.DramaDaoImpl;
import com.gc.server.dao.dramaeval.DramaEvalInfoDao;
import com.gc.server.dao.dramaeval.DramaEvalInfoDaoImpl;
import com.gc.server.dao.user.UserDao;
import com.gc.server.dao.user.UserDaoImpl;

public class GcServerManager implements GcManager{
	private UserDao userDao;
	private DramaDao dramaDao;
	private DramaEvalInfoDao dramaEvalInfoDao;
	
	public GcServerManager() {
		userDao = new UserDaoImpl();
		dramaDao = new DramaDaoImpl();
		dramaEvalInfoDao = new DramaEvalInfoDaoImpl();
	}

	@Override
	public void signUp(UserModel userModel) throws DuplicatedException {
		userDao.insertUser(userModel);
	}

	@Override
	public UserModel signIn(String id, String password) throws RecordNotFoundException, InvalidateException{
		return userDao.userLogin(id, password);
	}

	@Override
	public void evaluateDrama(DramaEvaluateModel dem) throws CantEvaluateException{
		dramaEvalInfoDao.evaluateDrama(dem.getDramaId(), dem.getUserId(), dem.getComment(), dem.getEvaluateRate());
	}

	@Override
	public List<DramaModel> getRecommendDrama(String userId) {
		return dramaEvalInfoDao.getRecommendedDrama(userId);
	}

	@Override
	public void updateUser(UserModel userModel) throws RecordNotFoundException{
		userDao.updateUser(userModel);
		
	}

	@Override
	public List<DramaModel> searchDrama(String title) {
		return dramaDao.searchDrama(title);
	}

	@Override
	public boolean deleteDrama(Integer dramaId) {
		return dramaDao.deleteDrama(dramaId);
	}

	@Override
	public void registDrama(DramaModel dramaModel) throws DuplicatedException {
		dramaDao.insertDrama(dramaModel);
	}

	@Override
	public void updateDrama(DramaModel dramaModel)
			throws RecordNotFoundException {
		dramaDao.updateDrama(dramaModel);
	}

	@Override
	public List<DramaModel> searchDramas() {
		return dramaDao.searchDramas();
	}

	@Override
	public List<DramaModel> searchDramas(String userId) {
		return dramaDao.searchDramas(userId);
	}

	@Override
	public DramaModel searchDetailDrama(Integer dramaId, String userId) {
		return dramaDao.searchDetailDrama(dramaId, userId);
	}


}
